﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CodeToolBox.Form
{
    public partial class MenuDBForm : UIForm
    {
        public MenuDBForm()
        {
            InitializeComponent();
        }

        private void uiButton1_Click(object sender, EventArgs e)
        {
            try
            {
                string[] text_1 = text1.Text.Split("\n").Select(a => a.Trim()).ToArray();
                //string text_1r = text1.Text;
                string[] text_2 = text2.Text.Split("\n").Select(a => a.Trim()).ToArray();
                //string text_2r = text1.Text;

                // 找出text_1比text_2多出的内容
                string[] moreItems = text_1.Except(text_2).ToArray();
                text1_R.Text = string.Join("\n", moreItems);
                // 找出text_1比text_2少出的内容
                string[] lessItems = text_2.Except(text_1).ToArray();

                text2_R.Text = string.Join("\n", lessItems);

            }
            catch (Exception ex)
            {

                ShowErrorNotifier(ex.Message, true, 5000);
            }
        }

        private void uiButton2_Click(object sender, EventArgs e)
        {
            text1.Text = "";
            text1_R.Text = "";
            text2.Text = "";
            text2_R.Text = "";
        }

        private void text1_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(text1.Text)==false)
            {
                string[] text_1 = text1.Text.Split("\n").Select(a => a.Trim()).ToArray();
                if (text_1.Length > 0)
                {
                    label1.Text = $"text1({text_1.Length})";
                }
                else
                {
                    label1.Text = $"text1";
                }
            }
            

        }

        private void text2_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(text2.Text) == false)
            {
                string[] text_2 = text2.Text.Split("\n").Select(a => a.Trim()).ToArray();
                if (text_2.Length > 0)
                {
                    label2.Text = $"text2({text_2.Length})";
                }
                else
                {
                    label2.Text = $"text2";
                }
            }
        }

        private void text1_R_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(text1_R.Text) == false)
            {
                string[] text_1r = text1_R.Text.Split("\n").Select(a => a.Trim()).ToArray();
                if (text_1r.Length > 0)
                {
                    label1r.Text = $"text1比text2多的字段({text_1r.Length})";
                }
                else
                {
                    label1r.Text = $"text1比text2多的字段";
                }
            }
        }

        private void text2_R_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(text2_R.Text) == false)
            {
                string[] text_2r = text2_R.Text.Split("\n").Select(a => a.Trim()).ToArray();
                if (text_2r.Length > 0)
                {
                    label2r.Text = $"text1比text2少的字段({text_2r.Length})";
                }
                else
                {
                    label2r.Text = $"text1比text2少的字段";
                }
            }
        }
    }
}
